** Regressions

log using "$project_path/output/appendix_tables/Appendix_Table_C7.smcl", replace

use "$project_path/data/4_regdata/regdata.dta", clear

// Build outcomes
gen decade = Year - mod(Year, 10)
foreach decade in 1940 1950 1960 1970 1980 1990 2000 2010 {
	gen dummy_decade_`decade' = (decade==`decade')
}
gen dummy_africa = (Region=="Africa")
gen dummy_asia = (Region=="Asia")
gen dummy_easteur = (Region=="Eastern Europe")
gen dummy_lac = (Region=="Latin America and Caribbean")
gen dummy_oceania = (Region=="Oceania")
gen dummy_west = (Region=="Western Europe and North America")

// Regressions
rdrobust dummy_decade_1940 runvar, all
rdrobust dummy_decade_1950 runvar, all
rdrobust dummy_decade_1960 runvar, all
rdrobust dummy_decade_1970 runvar, all
rdrobust dummy_decade_1980 runvar, all
rdrobust dummy_decade_1990 runvar, all
rdrobust dummy_decade_2000 runvar, all
rdrobust dummy_decade_2010 runvar, all
rdrobust dummy_africa runvar, all
rdrobust dummy_asia runvar, all
rdrobust dummy_easteur runvar, all
rdrobust dummy_lac runvar, all
rdrobust dummy_oceania runvar, all
rdrobust dummy_west runvar, all

log close


** Building .tex table
#delimit ;
local varlist dummy_decade_1940
			  dummy_decade_1950
			  dummy_decade_1960
			  dummy_decade_1970
			  dummy_decade_1980
			  dummy_decade_1990
			  dummy_decade_2000
			  dummy_decade_2010
			  dummy_africa
			  dummy_asia
			  dummy_easteur
			  dummy_lac 
			  dummy_oceania
			  dummy_west
;
#delimit cr			  
			  
			  
local rows : word count `varlist'
//Prepare matrix of coefficients and other statistics
local nrows `rows'
local ncols 4
mat Coefs = J(`nrows', `ncols', .)

local i = 1			  
foreach var in `varlist'{

	rdrobust `var' runvar, all
	//Store estimates and stats
	local b_`i': di %5.3f e(tau_cl)
	local se_`i': di %5.3f e(se_tau_rb)
	local p_`i': di %5.3f e(pv_rb)
	loca N_`i': di %6.0f e(N)
	
	//Fill the matrix
	mat Coefs[`i',1] = `b_`i''
	mat Coefs[`i',2] = `se_`i''
	mat Coefs[`i',3] = `p_`i''	
	mat Coefs[`i',4] = `N_`i''
	
	local ++i
	
}			  

mat list Coefs

********************************************************************************
* 								EXPORT TABLE
********************************************************************************			
// Clear the dataset, and use the matrix as dataset			

clear
svmat Coefs

rename Coefs1 estimates
rename Coefs2 std_err
rename Coefs3 pval
rename Coefs4 N

label var estimates "Est."
label var std_err "SE"
label var pval "p-val"
label var N "N"

gen outcome = ""

replace outcome = "1940s decade dummy" in 1
replace outcome = "1950s decade dummy" in 2
replace outcome = "1960s decade dummy" in 3
replace outcome = "1970s decade dummy" in 4
replace outcome = "1980s decade dummy" in 5
replace outcome = "1990s decade dummy" in 6
replace outcome = "2000s decade dummy" in 7
replace outcome = "2010s decade dummy" in 8
replace outcome = "Africa dummy" in 9
replace outcome = "Asia dummy" in 10
replace outcome = "Eastern Europe dummy" in 11
replace outcome = "Latin America and Caribbean dummy" in 12
replace outcome = "Oceania dummy" in 13
replace outcome = "Western Europe and North America dummy" in 14

label var outcome "Outcome"

order outcome, first

tostring estimates, replace force format(%04.3f)

//Add stars
local 3_star 0.01
local 2_star 0.05
local 1_star 0.10

replace estimates = estimates + "***" if pval < `3_star'
replace estimates = estimates + "**" if  pval < `2_star' & pval > `3_star'
replace estimates = estimates + "*" if   pval < `1_star' & pval > `2_star'

foreach var in std_err pval{
	
	tostring `var', replace force format(%04.3f)
	
}

replace std_err = "(" + std_err + ")"
replace pval = "[" + pval + "]"


local title "Placebo tests: Effects on decade and regional dummies"
local label_key "tab:placebo_decade_region"
local output "$project_path/output/appendix_tables/Appendix_Table_C7.tex"
local footnote = "\emph{Notes}: This table reports estimates for equation (\ref{eq:baseline_rdd}), using decade and regional dummies as dependent variables."

texsave using "`output'", replace varlabels frag nofix 	location(h) ///
					      align(p{10cm} p{1.7cm} p{1.7cm} p{1.7cm} p{1.7cm}) ///
						  title("`title'")  ///
						  footnote("`footnote'") ///
						  marker("`label_key'") 
			





	








